9 const int maxBoxes
= 1000;
10 const int maxLoad
= 3000;
11 int dp
[maxBoxes
][maxLoad
+1];
13 dp[i][j] = Máxima cantidad de cajas que puedo apilar
14 tal que la caja i-ésima esté encima y que pueda montar
17 int w
[maxBoxes
], l
[maxBoxes
];
21 while (cin
>> n
&& n
){
23 for (int i
=0; i
<n
; ++i
)
24 for (int j
=0; j
<=maxLoad
; ++j
)
29 for (int i
=0; i
<n
; ++i
){
31 for (int j
=0; j
<= l
[i
]; ++j
){
33 if (j
+ w
[i
] <= maxLoad
){
34 for (int k
=0; k
<i
; ++k
){
35 dp
[i
][j
] = std::max(dp
[i
][j
], dp
[k
][j
+w
[i
]] + 1);
39 answer
= std::max(answer
, dp
[i
][0]);
41 cout
<< answer
<< endl
;